package com.zhanghe.study.spring4.beans.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author zh
 * @date 2021/1/30 18:30
 */
public class MyProcessor implements BeanPostProcessor {

    /**
     * 初始化之前
     * @param o
     * @param s
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        if(o instanceof Connection){
            System.out.println("初始化之前");
        }
        return o;
    }

    /**
     * 初始化之后
     * @param o
     * @param s
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        if(o instanceof Connection){
            System.out.println("初始化之后");
        }
        return o;
    }
}
